package com.pwser.consumer.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.pwser.common.entities.Dept;
import com.pwser.common.interf.DeptServiceInterf;
import com.pwser.common.interf.DeptServiceInterf2;

@RestController
public class ConsumerController {

	@Autowired
	private DeptServiceInterf deptService;

	@Autowired
	private DeptServiceInterf2 deptService2;

	@GetMapping(value = "/feign/dept/add")
	public boolean add(Dept dept) {
		return deptService.add(dept);
	}

	@GetMapping(value = "/feign/dept/get/{id}")
	public Dept get(@PathVariable("id") Long id) {
		return deptService.get(id);
	}

	@GetMapping(value = "/feign/dept/list")
	public List<Dept> list() {
		return deptService.list();
	}

	@GetMapping(value = "/feign/dept/discovery")
	public List<String> discovery() {
		return deptService.discovery();
	}

	@GetMapping(value = "/feign/dept/discovery/{serviceId}")
	public List<ServiceInstance> getServiceById(@PathVariable("serviceId") String serviceId) {
		return deptService.getServiceById(serviceId);
	}

	@GetMapping(value = "/feign/pro/list")
	public List<Dept> listPro() {
		return deptService2.listPro();
	}

	@GetMapping(value = "/feign/dept/avalanche")
	public List<Dept> avalanche() throws InterruptedException {
		return deptService.avalanche();
	}

	@GetMapping(value = "/feign/dept/info")
	public String getInfo() {
		return "服务雪崩效应缓解了...";
	}

}
